import type {VerifyUserResponse} from "@/types/loginVerfiy"
import {request} from "@/utils/request"
import type {Captcha} from "@/interface/Captcha";

/**
 * 验证用户操作
 * @returns 图片验证
 */
export const verifyUserApi = () => {
    return request<VerifyUserResponse>({
        method: 'GET',
        url: '/user/verify'
    })
}

/**
 * 验证用户选择是否正确
 * @param answer 发送验证的答案
 * @returns
 */
export const submitVerifyApi = (answer: number[]) => {
    return request({
        method: 'POST',
        url: '/verify',
        data: answer
    })
}

/**
 * get captcha
 */
export const getCaptchaApi = () => {
    return request<Captcha>({
        url: '/captcha/get',
        method: 'POST'
    })
/*    return new Promise<string>((resolve, reject) => {
        uni.request({
            url: '/captcha/get',
            method: 'POST',
            success: (res) => {
                console.log(res)
                // 获取地址
                let base64Image = 'data:image/png;base64,' + res.data.data
                resolve(base64Image)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })*/

}

/**
 * check captcha
 * @param code the captcha entered by the user
 */
/*export const checkCaptchaApi = (code: string) => {
    return request({
        method: 'POST',
        url: `/captcha/check?code=${code}`,
    })
}*/
